package models

import "time"
import "gorm.io/gorm"
import "go_part/utils"
//import "fmt"

type ApprovalType struct{
	gorm.Model
	Name string
	ApprovalID string
	CompanyID string
	LoginTime time.Time
	IsLogout bool
	DeviceInfo string
 }

func (table *ApprovalType) TableName() string {

	return "approval_type_basic"
}

func GetApprovalTypeList() []*ApprovalType { 
	data := make([]*ApprovalType,10)
	utils.DB.Find(&data)
	// for _,v : = range data {
	// 	fmt.Println(v)
	// }
	return data
}

func FindApprovalTypeByName(name string) ApprovalType {
	user := ApprovalType{}
	utils.DB.Where("name = ?",name).Find(&user)
	return user
}

func FindApprovalTypeByID(id uint) ApprovalType {
	user := ApprovalType{}
	utils.DB.Where("id = ?",id).First(&user)
	return user
}

func FindApprovalTypeByIDAndCompanyID(id uint,CompanyID string) ApprovalType {
	user := ApprovalType{}
	utils.DB.Where("id = ? and company_id = ?",id,CompanyID).First(&user)
	return user
}

func FindApprovalTypeByDeviceIDAndCompanyID(id string,CompanyID string) ApprovalType {
	user := ApprovalType{}
	utils.DB.Where("approval_id = ? and company_id = ?",id,CompanyID).First(&user)
	return user
}

func FindApprovalTypeByCompanyID(id string) []*ApprovalType {
	user := make([]*ApprovalType,100)
	utils.DB.Where("company_id = ?",id).Find(&user)
	return user
}

func CreateApprovalType(user ApprovalType) *gorm.DB {
	
	return utils.DB.Create(&user)
}

func DeleteApprovalType(user ApprovalType) *gorm.DB {
	
	return utils.DB.Delete(&user)
}

func UpdateApprovalType(user ApprovalType) *gorm.DB {
	
	return utils.DB.Model(&user).Updates(ApprovalType{Name: user.Name,DeviceInfo: user.DeviceInfo})
}